<template>
    <div class="mask">
        <div class="TMB-warp">
            <div class="titler">
                <span class="font-w fs16" style="font-weight: 700;">一括削除</span>
                <i class="el-icon-close" @click="CloseTables"></i>
            </div>
            <div class="middle">
                <div class="router">
                    <i class="el-icon-search" @click="initFn()"></i>
                    <el-input size="mini" style="width: 190px;" v-model="searchTxt"></el-input>
                    <span>
                        対象：
                    </span>
                    <el-select placeholder=" " v-model="macType" size="mini" @change="initFn(macType)">
                        <el-option v-for="item in macTypeList" :key="item.key" :label="item.label" :value="item.key">
                        </el-option>
                    </el-select>
                </div>
                <ux-grid class="ux-table" ref="singleTable" :data="tableData" :header-cell-style="{
                    color: 'rgba(0, 0, 0, 0.85)',
                    fontSize: '14px',
                    textAlign: 'left',
                    fontWeight: 'bold',
                    padding: 0,
                    height: '32px',
                    background: 'rgb(244,245,246)'
                }" :cell-style="{
                    color: 'rgba(96,98,102,1)',
                    fontSize: '14px',
                    textAlign: 'left',
                    padding: 0,
                    height: '32px',
                }" :checkbox-config="{
                    showHeader: true,
                }" @selection-change="handleSelectionChange" @current-change="handleCurrentChange"
                    highlight-current-row v-loading="loading" element-loading-spinner="el-icon-loading"
                    element-loading-background="#f8f8f8" :element-loading-text="$t('message.bhView.loading')"
                    height="500">
                    <template slot="empty"> No data </template>
                    <ux-table-column type="checkbox" width="40" align="center" title="">
                    </ux-table-column>
                    <ux-table-column property="label" align="center" :title="macType == 1 ? '機器番号' : 'スプールNo.'" width="150"
                        show-overflow>
                        <template slot-scope="scope">
                            {{ scope.row.macNumb }}
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="肉厚仕樣">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.thckUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="工事計画">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.conplanUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="検査計画">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.viplanUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="肉厚計画">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.thckplanUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="要約">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.sumaccUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="詳細結果">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.viaccUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                    <ux-table-column property="label" align="center" title="肉厚結果">
                        <template slot-scope="scope">
                            <div class="center">
                                <img style="width: 35px; height: 35px; padding: 10px"
                                    :src="scope.row.thckaccUmu == 1 ? checkImg : uncheckImg" alt="" />
                            </div>
                        </template>
                    </ux-table-column>
                </ux-grid>
                <div class="footer">
                    <div>
                        <span style="margin-right: 12px;">件数 = {{ tableData.length }}</span>
                        <span>対象点数 = {{ selectionArr.length }} 件</span>
                    </div>
                    <div>
                        <el-button type="default" size="mini" @click="CloseTables">Cancel</el-button>
                        <el-button type="primary" size="mini" @click="okFn">OK</el-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BASE from '@/utils/base'
import { getDeviceDeleteBulkList, getDelDeviceDeleteBulkTipsMsg, delDeviceDeleteBulk } from '@/api/api'
import eventBus from "@/eventBus/bus";

export default {
    name: "RightTabelShow",
    data() {
        return {
            tableData: [],
            loading: false,
            selectionArr: [],
            checkImg: require("@/assets/img/checkbox_sel.png"),
            uncheckImg: require("@/assets/img/checkbox_unsel.png"),
            macTypeList: [
                {
                    label: '機器',
                    key: 1
                },
                {
                    label: '配管',
                    key: 2
                },
            ],
            macType: Number(this.$store.state.macType),
            searchTxt: ''
        };
    },
    props: ["PltCode"],// 1列表2列表-图形
    components: {},
    watch: {},
    methods: {

        handleSelectionChange(e) {
            console.log(e);
            this.selectionArr = e;
        },
        handleCurrentChange(val) {
            console.log(val);

        },

        async okFn() {
            if (this.selectionArr.length == 0) {
                return
            }
            let dataJson = {
                MacType: this.$store.state.macType
            }
            let res = await getDelDeviceDeleteBulkTipsMsg(dataJson);
            if (res.data.code == 451) {
                this.$confirm(res.data.msg, '', {
                    confirmButtonText: 'OK',
                    cancelButtonText: 'Cancel',
                    type: 'warning'
                }).then(async () => {
                    let dataJson = this.selectionArr.map(item => {
                        return Number(item.dmgCode)
                    })
                    let res = await delDeviceDeleteBulk({ DmgCode: dataJson });
                    if (res.data.code == 0) {
                        this.$message.success(res.data.msg);
                        this.$emit('reGetFn');
                        this.$emit('showTab1DelFlgFn');
                    } else {
                        this.$alert(res.data.msg, '', {
                            confirmButtonText: 'OK',
                            type: 'warning',
                        });

                    }
                }).catch(() => {

                });
            }
        },
        CloseTables() {
            this.$emit('showTab1DelFlgFn');
        },

        async initFn(MacType = this.$store.state.macType) {
            this.tableData = [];
            this.$store.commit("changeMacType", MacType);
            this.loading = true;
            let dataJson = {
                PltCode: this.PltCode,
                MacType,
                MacNumb: this.searchTxt
            }
            let res = await getDeviceDeleteBulkList(dataJson);
            this.loading = false;
            this.tableData = res.data.data;
        },

    },
    created() { },
    mounted() {
        this.initFn();
    },
    updated() {
        // 使用querySelectorAll选中所有带有.elx-cell--checkbox类的元素
        var elements = document.querySelectorAll('.elx-cell--checkbox');

        // 遍历这些元素  
        elements.forEach(function (element) {
            // 修改每个元素的title属性  
            element.setAttribute('title', '');
        })
    },
    beforeDestroy() { },
    destroyed() { }
};
</script>
<style lang="scss" scoped>
.mask {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;


}

.TMB-warp {
    width: 800px;
    background: rgb(255, 255, 255);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
        0px 9px 28px 0px rgba(0, 0, 0, 0.08), 0px 6px 16px -8px rgba(0, 0, 0, 0.15);
    z-index: 100;

    .titler {
        height: 43px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 13px 24px;
        border-bottom: 1px solid #F0F0F0FF;

        i {
            cursor: pointer;
        }
    }

    .middle {
        padding: 13px 24px;

        .router {
            padding-bottom: 13px;
            display: flex;
            align-items: center;

            * {
                margin-right: 12px;
            }

            .el-icon-search {
                width: 24px;
                height: 24px;
                border-radius: 4px;
                border: 1px solid #d9d9d9;
                display: flex;
                align-items: center;
                justify-content: center;
                cursor: pointer;
            }
        }

        .title {
            display: flex;
            margin-bottom: 13px;

            .form-ipt {
                height: 24px;

                ::v-deep .el-input__inner {
                    width: 197px;
                    height: 24px;
                    background: #fff;
                }
            }
        }



        ::v-deep .elx-table {
            border: 1px solid #00000026;
        }

        .table {
            border-bottom: 1px solid red !important;
        }

        .center {
            text-align: center;
        }

        .footer {
            height: 43px;
            background-color: #EDEEEFFF;
            // border: 1px solid #00000026;
            // border-top: none;
            margin-top: 15px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 4px;
        }
    }
}

.iconfont {
    font-size: 24px;
    margin: 0 8px;
}

.tableIcon {
    font-size: 20px;
    margin: 0 4px;
}

.el-breadcrumb__item {
    cursor: pointer;
}
</style>
